//
//  ViewController.m
//  DeepBreathing
//
//  Created by rimi on 15/12/14.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "ViewController.h"

#import "ASD.h"
#import "ANnimationController.h"



@interface ViewController ()
@property(nonatomic,strong)ANnimationController *animation;


@end

@implementation ViewController

//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    
//    ANnimationController *animation =  [[ANnimationController alloc]init];
//    
//    self.animation = animation;
//    self.navigationController.delegate =animation;
//    [self.navigationController pushViewController:[[ViewController alloc]init] animated:YES];
//    
//    
//    
//}

- (void)viewDidLoad {
    [super viewDidLoad];
//    
//        ASD *view = [[ASD alloc]initWithFrame:CGRectMake(80, 80, 100, 100)];
//        view.backgroundColor  = [UIColor whiteColor];
    
    self.view.backgroundColor = [UIColor colorWithRed:1.0 green:0.6879 blue:0.6588 alpha:1.0];
//        [self.view addSubview:view];
//
//        view.didCilckBlock = ^(CGPoint location){
//    
//            NSLog(@"%@",NSStringFromCGPoint(location));
//        };

    //4要素， 动什么，持续时间，起始 结束
//    CABasicAnimation *animation = [CABasicAnimation animation];
//    
//    animation.keyPath = @"position";
//    animation.duration = 1;
//    //如果不设置to model的属性就是to
//    animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(80, 80)];
//    
////    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 300)];
//    animation.beginTime = CACurrentMediaTime() + 2;
//    animation.fillMode = kCAFillModeBoth;
//    
//    animation.removedOnCompletion = NO;
////    animation.fillMode = kCAFillModeForwards;
//    
//    animation.delegate = self;
//    UIBezierPath *bazierPath = [UIBezierPath bezierPathWithArcCenter:<#(CGPoint)#> radius:<#(CGFloat)#> startAngle:<#(CGFloat)#> endAngle:<#(CGFloat)#> clockwise:<#(BOOL)#>]
    
//    UIBezierPath *bazierPath = [UIBezierPath bezierPath];
////    
////    [bazierPath addLineToPoint:<#(CGPoint)#>]
//    
//    UIBezierPath *bazierPath1 = [UIBezierPath bezierPathWithOvalInRect:];
//    [bazierPath appendPath:<#(nonnull UIBezierPath *)#>];//直线拼接圆
    
    //剪切
//    UIGraphicsBeginImageContext(CGSizeZero)
//    [self.view addSubview:view];
//    UIBezierPath *sinPath = [UIBezierPath bezierPath];
//    
//    CGFloat width = CGRectGetWidth(self.view.bounds);
//    CGFloat height = CGRectGetHeight(self.view.bounds);
//    [sinPath moveToPoint:CGPointMake(0, height/2)];
//    for (int i  = 0; i < 2 * width; i++) {
//        CGFloat x = i;
//        CGFloat y = -height/2 * sin(x/(width/(2*M_PI))) + height/2;
//                                    [sinPath addLineToPoint:CGPointMake(x, y)];
//    }
//    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
//    shapeLayer.frame =self.view.bounds;
//    shapeLayer.lineWidth = 2;
//    shapeLayer.strokeColor = [UIColor blueColor].CGColor;
//    shapeLayer.fillColor  = [UIColor clearColor].CGColor;
//    shapeLayer.backgroundColor = [UIColor clearColor].CGColor;
//    shapeLayer.path = sinPath.CGPath;
//    [self.view.layer addSublayer:shapeLayer];
//    
//    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animation];
//    
//    pathAnimation.keyPath = @"position";
//    pathAnimation.duration = 3;
//    pathAnimation.path = sinPath.CGPath;
//    
//    pathAnimation.rotationMode = kCAAnimationRotateAuto;
//    
//    [view.layer addAnimation:pathAnimation forKey:nil];
    
    
//    [view.layer addAnimation:animation forKey:nil];
    
//    [UIView transitionWithView:self.view duration:2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//        
//    } completion:^(BOOL finished) {
//        
//    }];
//
//    
//    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
//    
//    gradientLayer.frame = self.view.frame;
    
//    gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:250.f/255.f  green:159.f/255 blue:81.f/255 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:249.f/255  green:210.f/255 blue:102.f/255 alpha:1.0].CGColor];
    //设置Model layer
//    gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:43.f/255 green:40.f/255 blue:143.f/255 alpha:1].CGColor,(__bridge id)[UIColor colorWithRed:103.f/255 green:32.f/255 blue:229.f/255 alpha:1].CGColor];
//    
//    gradientLayer.startPoint = CGPointMake(0, 0);
//    gradientLayer.endPoint = CGPointMake(0, 1);
//    
//    
//    [self.view.layer addSublayer:gradientLayer];
//    CABasicAnimation *animation = [CABasicAnimation animation];
//    
//    animation.keyPath  = @"colors";
//    
//    animation.duration = 2.8;
//    
//    animation.fromValue  = @[(__bridge id)[UIColor colorWithRed:250.f/255.f  green:159.f/255 blue:81.f/255 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:249.f/255  green:210.f/255 blue:102.f/255 alpha:1.0].CGColor];
//    animation.beginTime = CACurrentMediaTime() + 1;
//    
//    animation.fillMode = kCAFillModeBackwards;
////  [gradientLayer addAnimation:animation forKey:nil];
//    gradientLayer.mask  =[self shape];
//
    [self shape];
//
//    
}
//
-(CAShapeLayer *)shape{
//
//    static CGFloat height = 234;
    static CGFloat height2 = 50;
    CGFloat witdh = CGRectGetWidth(self.view.bounds);
//
//    
//        UIBezierPath *frompath = [UIBezierPath bezierPath];
//    [frompath moveToPoint:CGPointZero];
//    [frompath addLineToPoint:CGPointMake(0, height)];
//    [frompath addQuadCurveToPoint:CGPointMake(witdh, height) controlPoint:CGPointMake(witdh/2, 490)];
//    [frompath addLineToPoint:CGPointMake(witdh, 0)];
//    [frompath closePath];
//    
    UIBezierPath *topath = [UIBezierPath bezierPath];
    
    [topath moveToPoint:CGPointZero];
    
    [topath addLineToPoint:CGPointMake(200, 50)];
    [topath addQuadCurveToPoint:CGPointMake(200, 120) controlPoint:CGPointMake(200, 220)];
    [topath addLineToPoint:CGPointMake(200, 250)];
    
    [topath closePath];
//
//    
//    
//    
//    
//    
//    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = CGRectMake(100, 100, 100, 100);
    shapeLayer.backgroundColor  =  [UIColor colorWithRed:1.0 green:0.8553 blue:0.9443 alpha:1.0].CGColor;
    shapeLayer.fillColor = [UIColor colorWithRed:1.0 green:0.5953 blue:0.5756 alpha:1.0].CGColor;
    shapeLayer.strokeColor  =  [UIColor colorWithRed:1.0 green:0.9395 blue:0.8502 alpha:1.0].CGColor;
    shapeLayer.lineWidth = 5;
    shapeLayer.path   = [UIBezierPath bezierPathWithOvalInRect:shapeLayer.bounds].CGPath;
    shapeLayer.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50) radius:100 - 2.5 startAngle:0 endAngle:2 * M_PI clockwise:YES].CGPath;
    shapeLayer.path = topath.CGPath;

    [self.view.layer addSublayer:shapeLayer];
//
//    CABasicAnimation *animation = [CABasicAnimation animation];
//    
//    animation.keyPath  = @"path";
//    animation.duration = 2.8;
//    animation.fromValue = (__bridge id _Nullable)(frompath.CGPath);
//    animation.beginTime = CACurrentMediaTime() + 1;
//    animation.fillMode =kCAFillModeBackwards;
//    
//    [shapeLayer addAnimation:animation forKey:nil];
//    
    return shapeLayer;
//
//    
//}
//
//-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
//    CAAnimation *animation = [self.view.layer animationForKey:@"abc"];
//    
//    if (animation == anim) {
//        
//        
//        
//        
}


@end
